package JDBC.快速入门代码;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

@SuppressWarnings("all")
public class index {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //注册驱动
        //MySQL5之后，这段代码可以不写
        //Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/jdbc_study";
        String user = "root";
        String password = "lyx254254";
        Connection cnt = DriverManager.getConnection(url, user, password);

        //定义SQL语句
        String sql = """
                update account
                set money = 2000
                where name = '张三';
                """;

        //获取执行SQL的对象
        Statement sta = cnt.createStatement();

        //执行SQL语句
        int line = sta.executeUpdate(sql);

        //处理返回结果
        System.out.println(line + "行受到影响");

        //释放资源
        sta.close();
        cnt.close();

    }
}
